package hu.elte.inf.holiuml.gui;

import hu.elte.inf.holiuml.model.ClassDiagram;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.Vector;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class CodeGeneratorOptionsDialog extends OptionsDialog{
	
	Vector<ClassDiagram> classDiagrams;
	JPanel propPanel;
	JComboBox nameCombo;
	protected CodeGeneratorOptionsDialog(HoliUML parent, String title, Vector<ClassDiagram> classDiagrams) {
		super(parent, title);
		this.classDiagrams = classDiagrams;
		createPropPanel();
		fillPanels();
		setModalityType(ModalityType.APPLICATION_MODAL);
		setSize(new Dimension(450,120));
		setVisible(true);
	}

	private void createPropPanel(){
		propPanel = new JPanel(new GridLayout(1,2));
		nameCombo = new JComboBox();
		for(int i = 0; i < classDiagrams.size(); i++){
			nameCombo.addItem(classDiagrams.get(i).getName());
		}
		if(classDiagrams.size() != 0){
			nameCombo.setSelectedIndex(0);
		}
		//adding to the panel
		propPanel.add(new JLabel("The name of the classdiagram:"));
		propPanel.add(nameCombo);	
	}
	private void fillPanels(){
		getContentPane().setLayout(new BorderLayout());
		getContentPane().add("North", propPanel);
		getContentPane().add("South", buttonPanel);
	}
	public ClassDiagram getClassDiagram(){
		if(classDiagrams.size() != 0){
			return classDiagrams.get(nameCombo.getSelectedIndex());
		}
		return null;
	} 
	@Override
	protected void processCancel() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected boolean processOK() {
		if(classDiagrams.size() == 0){
			JOptionPane.showMessageDialog(parent, "There is no class diagram!", "Error!", JOptionPane.ERROR_MESSAGE);
			return false;
		}else{
			return true;
		}
	}

}
